package com.xqboss.apps.domain.marketing;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xqboss.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Date;
import java.util.stream.Stream;

/**
 * <p>
 *
 * </p>
 *
 * @author fu.yang
 * @since 2022-08-08
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value = "MarketingRightsCard对象", description = "")
public class MarketingRightsCard extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "卡片名称")
    private String title;

    @ApiModelProperty(value = "权益卡类型  1: 优先购")
    private Integer type;

    @ApiModelProperty(value = "赠送总次数")
    @Min(value = 1, message = "赠送总次数不得小于1")
    private Integer timesCount;

    @ApiModelProperty(value = "发放方式 1:一次性到账 2:按日到账 3:按周到账 4: 按月到账")
    private Integer grantMethod;

    @ApiModelProperty(value = "发放日期 按周发放(1-7) 按月发放(1-30)")
    @Min(value = 1)
    @Max(value = 30)
    private Integer grantDate;

    @ApiModelProperty(value = "每次发放时发放的次数")
    @Min(value = 1, message = "次数不得小于1")
    private Integer everyTime;

    @ApiModelProperty(value = "初始库存")
    @Min(value = 1, message = "库存不得小于1")
    private Integer stock;

    @ApiModelProperty(value = "当前库存")
    private Integer currentStock;

    @ApiModelProperty(value = "排序标志")
    private Integer sortSign;

    @ApiModelProperty("已使用数量")
    private Integer usedNum;

    @ApiModelProperty(value = "发放状态 0:未发放 1:发放中 2:已作废 3:发放完毕")
    private Integer status;

    @JsonIgnore
    @TableLogic(value = "null",delval = "now()")
    protected Date deleteTime;
    /**
     * 权益卡类型枚举
     */
    public enum TypeEnum {
        PRIORITY_BUY(1, "优先购"),
        ;

        private int value;
        private String name;

        TypeEnum(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        public static String getSeparator() {
            return "次 | ";
        }

        public static TypeEnum getByValue(int value) {
            return Stream.of(TypeEnum.values())
                    .filter(v -> v.getValue() == value)
                    .findAny().orElse(null);
        }

    }


    /**
     * 权益卡状态
     */
    public enum StatusEnum {

        NOT_START(0, "未发放"),
        GRANTING(1, "发放中"),
        CANCELLATION(2, "已作废"),
        FINISHED(3, "发放完毕"),
        ;

        private int value;
        private String name;

        StatusEnum(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        public static String getSeparator() {
            return " | ";
        }

        public static StatusEnum getByValue(int value) {
            return Stream.of(StatusEnum.values())
                    .filter(v -> v.getValue() == value)
                    .findAny().orElse(null);
        }

    }


    /**
     * 权益卡发放方式枚举
     */
    public enum GrantMethodEnum {
        SINGLE_USE(1, "一次性到账"),
        BY_THE_DAY(2, "按日到账"),
        BY_THE_WEEK(3, "按周到账"),
        BY_THE_MONTH(4, "按月到账");

        private int value;
        private String name;

        GrantMethodEnum(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        /**
         * 获取按周发放模板
         */
        public static String getWeekTemp() {
            return "每周%s发放%s次";
        }

        /**
         * 获取按月发放模板
         */
        public static String getMonthTemp() {
            return "每月%s号发放%s次";
        }

        /**
         * 获取按日发放模板
         */
        public static String getDayTemp() {
            return "每天发放%s次";
        }

        public static GrantMethodEnum getByValue(int value) {
            return Stream.of(GrantMethodEnum.values())
                    .filter(v -> v.getValue() == value)
                    .findAny().orElse(null);
        }

    }

}
